using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace DataLayerTest.Models.Mapping
{
    public class CheerMessageMap : EntityTypeConfiguration<CheerMessage>
    {
        public CheerMessageMap()
        {
            // Primary Key
            this.HasKey(t => new { t.Id, t.IdGroup });

            // Properties
            this.Property(t => t.Id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.IdGroup)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.Text)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.ImageUrl)
                .HasMaxLength(50);

            this.Property(t => t.SoundUrl)
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("CheerMessage");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.IdGroup).HasColumnName("IdGroup");
            this.Property(t => t.Text).HasColumnName("Text");
            this.Property(t => t.ImageUrl).HasColumnName("ImageUrl");
            this.Property(t => t.SoundUrl).HasColumnName("SoundUrl");

            // Relationships
            this.HasRequired(t => t.CheerMessagesGroup)
                .WithMany(t => t.CheerMessages)
                .HasForeignKey(d => d.IdGroup);

        }
    }
}
